package com.en.config;


import com.microsoft.cognitiveservices.speech.SpeechConfig;
import com.microsoft.cognitiveservices.speech.SynthesisVoicesResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import com.microsoft.cognitiveservices.speech.SpeechSynthesizer;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.Future;

/**
 * ClassName: WxPayConfig
 * Package: com.question.config
 * Description:
 *
 * @Date: 2023/12/29 23:14
 * @Author: wht
 */
@Configuration
public class VoiceConfig {
    @Autowired // 注入 ResourceLoader 对象
    private ResourceLoader resourceLoader;
//    public static String speechKey;
//    public static String speechRegion;

    public static SpeechSynthesizer synthesizerUSJennyNeural;

    public static SpeechSynthesizer synthesizerZHXiaoxiaoNeural;


    @PostConstruct
    public void getSpeechConfig() throws IOException {
        // 获取properties文件里的敏感数据--------------------
        Properties properties = new Properties();
        Resource resource = resourceLoader.getResource("classpath:GlobalConfig.properties");
        InputStream inputStream = resource.getInputStream();
        properties.load(inputStream);


        String speechKey = properties.getProperty("speechKey");
        String speechRegion = properties.getProperty("speechRegion");

        SpeechConfig speechConfigUSJennyNeural = SpeechConfig.fromSubscription(speechKey, speechRegion);

        speechConfigUSJennyNeural.setSpeechSynthesisLanguage("en-US");
        speechConfigUSJennyNeural.setSpeechSynthesisVoiceName("en-US-JennyNeural");
        synthesizerUSJennyNeural = new SpeechSynthesizer(speechConfigUSJennyNeural, null);

        speechConfigUSJennyNeural.setSpeechSynthesisLanguage("zh-CN");
        speechConfigUSJennyNeural.setSpeechSynthesisVoiceName("zh-CN-XiaoxiaoNeural");
        synthesizerZHXiaoxiaoNeural = new SpeechSynthesizer(speechConfigUSJennyNeural, null);



//       synthesizerUSJennyNeural.getVoicesAsync("aa").get().
    }
}
